# 导包
import requests

# 实例化session
session = requests.Session()
# 使用session获取验证码,获取之后,验证码数据会自动保存到session中
session.get(url="http://tpshop-test.itheima.net/index.php?m=Home&c=User&a=verify")
# 使用session登录
response = session.post(url="http://tpshop-test.itheima.net/index.php?m=Home&c=User&a=do_login",
                        headers={"Content-Type": "application/x-www-form-urlencoded"},
                        data="username=13800138006&password=123456&verify_code=8888")
# 打印结果
print(response.json())
# 关闭session
session.close()

# import requests
#
# session = requests.Session()
# session.get(url="http://tpshop-test.itheima.net/index.php?m=Home&c=User&a=verify")
# response = session.post(url="http://tpshop-test.itheima.net/index.php?m=Home&c=User&a=do_login",
#                         headers={"Content-Type": "application/x-www-form-urlencoded"},
#                         data="username=13800138006&password=123456&verify_code=8888")
# print(response.json())
# session.close()
